<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="请输入内容（最多120字）" maxlength="120" v-model="content"></textarea>
        <mt-button type="primary" size="large" @click="postComment">发表评论</mt-button>

        <div class="cmt-list">
            <div class="cmt-item" v-for="item in list" :key="item.time">
                <div class="cmt-title">
                    用户：{{item.name}}&nbsp;&nbsp;
                    发表时间：{{item.time}}
                </div>
                <div class="cmt-body">
                    {{item.content}}
                </div>
            </div>
            <div class="cmt-item">
                <div class="cmt-title">
                    用户：匿名用户&nbsp;&nbsp;
                    发表时间：2019-08-2
                </div>
                <div class="cmt-body">
                    基督教会但实际上就是大家
                </div>
            </div>
            <div class="cmt-item">
                <div class="cmt-title">
                    用户：匿名用户&nbsp;&nbsp;
                    发表时间：2019-08-13
                </div>
                <div class="cmt-body">
                    基督教会但实际上倒计时
                </div>
            </div>
            <div class="cmt-item">
                <div class="cmt-title">
                    第一楼&nbsp;&nbsp;
                    用户：匿名用户&nbsp;&nbsp;
                    发表时间：2019-08-10
                </div>
                <div class="cmt-body">
                    基督教会但实际上
                </div>
            </div>
        </div>

        <mt-button type="danger" size="large" plain="plain" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui'
    export default {
        name: "comment",
        data(){
            return {
                content:'',
                list:[
                    {name:'monee',content:'京哈大家还是大家',time:'2019-08-11'},
                    {name:'匿名用户',content:'京哈大家还是大家',time:'2019-08-1'},
                    {name:'匿名用户',content:'京哈大家还是大家',time:'2019-08-12'},
                ]
            }
        },
        methods:{
            getMore(){
                Toast('无更多评论')
            },
            postComment(){
                if(this.content.trim().length===0){
                    return Toast('评论内容不能为空')
                }
                this.list.unshift({name:'匿名用户',content:this.content.trim(),time:Date.now()})
                this.content=""
            }
        }
    }
</script>

<style scoped>
    .cmt-container h3 {
        font-size:18px;
    }
    textarea {
        font-size:14px;
        height: 85px;
        margin:0;
    }
    .cmt-item{
        font-size:13px;
        line-height:35px;
        margin: 5px 0 0 0;
    }
     .cmt-title{
        background-color: #ccc;
        padding-left: 2px;
    }
    .cmt-body{
        text-indent: 2em;
    }
</style>